library("ggplot2")
library("plotly")
keggdf <- read.csv("../kegg_analysis/kegg_to_path_output_null.txt", sep = "\t")
Sample of our data frame
head(keggdf)
## KEGG.Pathway Leaf58 pMPPla107
## 1 Global and overview maps 20 24
## 2 Drug resistance null 1
## 3 Immune diseases 1 1
## 4 Signaling molecules and interaction null 1
## 5 Cellular community null 1
## 6 Nucleotide metabolism 12 19
Plotly offers interactive charts when rendered in HTML. These charts show the counts of each KEGG pathway post UProC analysis.
#Note the showlegend option is set to false. After an update from plotly this needed to be added to avoid the legend crowding the chart for this format. However, just remove that command if the legend is desired.
pMP_pie <- plot_ly(keggdf, labels = ~KEGG.Pathway, values = ~pMPPla107, type = 'pie',textposition = 'outside',textinfo = 'value') %>%
layout(title = 'pMPPla107 KEGG Pathways', showlegend = FALSE,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
pMP_pie
L58_pie <- plot_ly(keggdf, labels = ~KEGG.Pathway, values = ~Leaf58, type = 'pie',textposition = 'outside',textinfo = 'value') %>%
layout(title = 'pBASL58 KEGG Pathways', showlegend = FALSE,
xaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE),
yaxis = list(showgrid = FALSE, zeroline = FALSE, showticklabels = FALSE))
L58_pie
Note: to add legend in R add ‘showlegend=TRUE’ after ‘title=“”,’. When rednering in markdown the legend overlaps the figure so I left it out here.
As previously mentioned plotly has some bugs, another of which includes the inability to export images within R studio. Therefore, another package is used for this task.
library("webshot")
export(pMP_pie, file = "imgage_name.png")
export(L58_pie, file = "imgage_name2.png")
For those that prefer a different graph to pie charts, lollipop graphs offer a nice visualization.
#Read in a comma serperated file
df <- read.csv("../kegg_analysis/kegg_output_lolipop_rm_some_paths.csv", header =TRUE, sep = ",")
head(df)
## Pathway Count Plasmid
## 1 Replication and repair 26 pMPPla107
## 2 Global and overview maps 24 pMPPla107
## 3 Replication and repair 22 pBASL58
## 4 Global and overview maps 20 pBASL58
## 5 Nucleotide metabolism 19 pMPPla107
## 6 Nucleotide metabolism 12 pBASL58
#Plot a grouped lolipop graph
ggplot(df)+
geom_linerange(aes(x = reorder(Pathway, Count), ymin = 0, ymax = Count, colour = Plasmid),
position = position_dodge(width = 0.5))+
geom_point(aes(x = reorder(Pathway, Count), y = Count, colour = Plasmid),
position = position_dodge(width = 0.5))+
coord_flip() +
xlab("KEGG Pathways")+
ylab("Number of Predicted Genes in Pathway")+
theme(axis.title = element_text(face = "bold"), legend.position = c(0.85,0.15))
Last updated 12/11/18